package pl.cba.solgar.game.rogal.commands;

import pl.cba.solgar.game.rogal.CommandRecognizer;
import pl.cba.solgar.game.rogal.Printable;
import pl.cba.solgar.game.rogal.Rogal;
import pl.cba.solgar.game.rogal.console.Console;
import pl.cba.solgar.game.rogal.utils.BinarySearchTree;

public class PrintCommandsCommand extends RogalCmd implements Printable {
	private PrintCommandsCommand instance;

	public PrintCommandsCommand(String keys, Rogal rogal, CommandRecognizer crec) {
		super(keys, rogal);
		instance = this;
		this.crec = crec;
		commands = new BinarySearchTree();
		crec.addCommand(new Exit(), commands);
	}

	public boolean execute() {
		crec.setCurrentDefaultCommand(new Command("") { public boolean execute() { return false; }});
		rogal.registerConsolePrintable(this);
		crec.setCurrentTree(commands);
		return false;
	}

	public String getShortDescription() {
		return "prints available commands";
	}

	public void print(Console c) {
		c.clear();
		crec.printCommands(c);
	}

	private class Exit extends Command {
		public Exit() { super("z"); }
		public boolean execute() {
			rogal.unregisterConsolePrintable(instance);
			return true;
		}
	}
}
